﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;







namespace INSTA.BankSystem.BLL
{
    /// <summary>
    /// A Person..
    /// </summary>
    
    public class Person 
    {
        private string      _name;
        private string      _firstName;
        private int         _yearOfBirth;

        /// <summary>
        /// Ctor
        /// </summary>
        public Person()
        {}

       
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="name">The name.</param>
        public Person(string name) 
            : this(name, "", 0) 
        {}

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="firstName">The first name.</param>
        public Person(string name, string firstName)
            : this(name, firstName, 0)
        { }


        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="firstName">The first name.</param>
        /// <param name="yob">The year of birth.</param>
        public Person(string name, string firstName, int yob)
        {
            Name = name;
            FirstName = firstName;
            YearOfBirth = yob;
        }




        /// <summary>
        /// Gets or sets the name.
        /// </summary>  
        public string Name
        {
            get { return _name; }
            set { _name = value.ToUpper(); }
        }

        /// <summary>
        /// Gets or sets the first name.
        /// </summary>
        public string FirstName
        {
            get { return _firstName; }
            set 
            {
                if (value.Length > 10)
                {
                    _firstName = value.Substring(0, 10);
                }
                else 
                {
                    _firstName = value;
                }

            }
        }


        /// <summary>
        /// Gets or sets the year of birth.
        /// </summary> 
        public int YearOfBirth
        {
            get { return _yearOfBirth; }
            set 
            {
                if (value < DateTime.Now.Year - 100
                    || value > DateTime.Now.Year)
                {
                    _yearOfBirth = -1;
                }
                else
                {
                    _yearOfBirth = value; 
                }
                
            }
            
        }

        /// <summary>
        /// Gets the age.
        /// </summary>
        public int Age
        {
            get
            {
                if (_yearOfBirth != -1)
                {
                    return DateTime.Now.Year - _yearOfBirth;
                }
                else
                {
                    return -1;
                }
            }
        }

        /*
        public override string ToString()
        {
            string formatString = "Name : {2}{0}, FirstName : {3}{0}, YearOfBirth : {4}{0}";

            return string.Format(formatString,
                                 "\r\n",
                                 Name,
                                 FirstName,
                                 YearOfBirth);
            
        }
         */
       
    }
}
